import React, {Fragment, PureComponent,} from 'react';
import {connect} from 'dva';
import moment from 'moment';
import router from 'umi/router';
import {Card, Form, Icon, Input, Select, Steps, Table,Row,Col,Button,Modal} from 'antd';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import styles from '../PrivateFile.less';
import DescriptionList from '@/components/DescriptionList';

const {Description} = DescriptionList;
const FormItem = Form.Item;
const {Step} = Steps;
const {TextArea} = Input;
const {Option} = Select;

/* eslint react/no-multi-comp:0 */
@connect(({publicModel, loading}) => ({
  publicModel,
  loading: loading.models.publicModel,
}))


@Form.create()
class Public extends PureComponent {
  state = {
    modalVisible: false,
    selectedRows: [],
    record: {},
    dataList: [{id: null, type: 'share', name: '共享文件'}],
  };

  showSubFiles = (row) => {
    saveMenuFrom("public_files_page");
    // saveMenuFrom("home_files_page");
    if (row.type == 'share') {
      //共享文件
      router.push('/filecenter/share');
    } else if (row.type == 'group') {
      router.push('/filecenter/group/' + row.id+'/' +row.name);
    }
  }

  columns = [
    {
      title: '文件名称',
      dataIndex: 'name',
      render: (text, row) => {
        return <Fragment>
          <Icon type="folder" theme="filled" style={{color: '#e87e04'}}/>
          &nbsp;<a onClick={() => this.showSubFiles(row)}>{text}</a>
        </Fragment>
      },
    },
  ]
  ;

  componentDidMount() {
    const {dispatch} = this.props;
    dispatch({
      type: 'publicModel/queryGroupList',
      callback: (res) => {
        if (res.result == "ok") {
          let groupList = res.data.dataList;
          let allList = [];
          // {id:1,type:'share/group',name:''}
          allList.push({id: null, type: 'share', name: '共享文件'})
          groupList.forEach(item => {
            allList.push({id: item.id, type: 'group', name: item.groupName})
          })
          this.setState({dataList: allList});
        } else {
          Modal.error({title: '操作失败', content: res.msg});
        }
      },
    });
  }

  renderSimpleForm() {
    const {
      form: {getFieldDecorator},
    } = this.props;

    return (
      <Form onSubmit={this.handleSearch} layout="inline">
        <Row gutter={{md: 8, lg: 24, xl: 48}}>
          <Col md={8} sm={24}>
            <FormItem label="文件名称">
              {getFieldDecorator('name')(<Input placeholder="请输入"/>)}
            </FormItem>
          </Col>
          <Col md={8} sm={24}>
            <span className={styles.submitButtons}>
              <Button type="primary" htmlType="submit">
                查询
              </Button>
            </span>
          </Col>
        </Row>
      </Form>
    );
  }

  renderForm() {
    return this.renderSimpleForm();
  }

  render() {
    const {
      publicModel: {},
      loading,
    } = this.props;
    const {dataList} = this.state;


    return (
      <PageHeaderWrapper title="公共文件">
        <Card bordered={false}>
          <div className={styles.tableList}>
            {/*<div className={styles.tableListForm}>{this.renderForm()}</div>*/}
            <Table className={styles.tdPadding} columns={this.columns} dataSource={dataList}/>
          </div>
        </Card>
      </PageHeaderWrapper>
    );
  }
}

export default Public;
